<?php
/**
 * Created by PhpStorm.
 * User: wiggin
 * Date: 2017/11/20
 */
namespace App\Utility;

class  MyConfInfo
{
    private $config = '';
    private static $_self = null;

    public function __construct()
    {
        $this->config = ROOT . '/Temp/config.php';
    }

    public static function getInstance()
    {
        if (is_null(self::$_self)) {
            self::$_self = new static();
        }
        return self::$_self;
    }

    public function getConfig($key = null)
    {
        $configInfo = array();
        $jsonConfig = file_get_contents($this->config);
        if (!empty($jsonConfig)) {
            $configInfo = json_decode($jsonConfig, true);
            if (!empty($key) && isset($configInfo[$key])) {
                return $configInfo[$key];
            }
        }
        return $configInfo;
    }

    public function setConfig($data)
    {
        if (empty($data)) {
            return false;
        }
        $jsonData = json_encode($data);
        return file_put_contents($this->config, $jsonData);
    }

}